package mvp.cklm.testtask.util;

import mvp.cklm.testtask.model.AddressModel;
import mvp.cklm.testtask.model.PhoneNumber;
import mvp.cklm.testtask.model.enums.PhoneType;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * User: valera
 * Date: 25.02.14
 * Time: 8:42
 */
public class FakeAddressCreator {
    private int counter = 0;
    private String[] countries = {"Ukraine", "Germany", "USA", "France", "Armenia", "Angola", "Dominicana", "Israel", "Jordan"};
    private String[] cities = {"Kiev", "Berlin", "Vashington", "Paris", "Yerevan", "Luanda", "Roseau", "Jerusalem", "Amman"};
    private PhoneNumber[] numbers = {new PhoneNumber(PhoneType.HOME, "011 380 56 554 44 98"),
            new PhoneNumber(PhoneType.MOBILE, "+380 097 768 57 98"),
            new PhoneNumber(PhoneType.HOME, "018 380 84 554 44 98"),
            new PhoneNumber(PhoneType.MOBILE, "+380 097 478 99 98"),
            new PhoneNumber(PhoneType.HOME, "078 380 84 554 44 98"),
            new PhoneNumber(PhoneType.MOBILE, "+380 050 478 99 98")};

    public FakeAddressCreator() {

    }

    public AddressModel createAddress() {
        List<PhoneNumber> newNumbers = new LinkedList<PhoneNumber>();
        Random r = new Random();
        int start = r.nextInt(numbers.length - 2);
        int stop = r.nextInt(numbers.length);
        for (int i = start; i < stop; i++) {
            newNumbers.add(numbers[i]);
        }
        if (newNumbers.isEmpty()) {
            newNumbers.add(numbers[start]);
        }
        int rcn = r.nextInt(countries.length);
        int rs = r.nextInt(400);
        int rh = r.nextInt(1000);
        int rf = r.nextInt(1000);
        return new AddressModel(++counter, countries[rcn], cities[rcn], "Street" + rs, rh, rf, "Random Address", newNumbers);
    }

    public AddressModel createAddress(int id) {
        List<PhoneNumber> newNumbers = new LinkedList<PhoneNumber>();
        Random r = new Random();
        int start = r.nextInt(numbers.length - 2);
        int stop = r.nextInt(numbers.length);
        for (int i = start; i < stop; i++) {
            newNumbers.add(numbers[i]);
        }
        if (newNumbers.isEmpty()) {
            newNumbers.add(numbers[start]);
        }
        int rcn = r.nextInt(countries.length);
        int rs = r.nextInt(400);
        int rh = r.nextInt(1000);
        int rf = r.nextInt(1000);
        return new AddressModel(id, countries[rcn], cities[rcn], "Street" + rs, rh, rf, "Random Address", newNumbers);
    }
}
